<?php

namespace App\Models\Chain\InviteCash;


use App\Models\Chain\AbstractHandler;
use App\Helpers\Logger\SLogger;
use App\Models\Chain\InviteCash\CheckIdentityVerify;
use DB;

/**
 *
 */
class DoIdentityHandler extends AbstractHandler
{
    #外部传参

    private $params = array();

    public function __construct($params)
    {
        $this->params = $params;
        $this->setSuccessor($this);
    }

    /**
     * @return mixed]
     */

    //1.判断是否已经完成身份加积分流水表
    //2.插入完成身份加积分流水表
    //3.插入积分日志表
    //4.更改用户积分表
    //4.判断是否是邀请用户
    //5.插入更新完成身份加现金表
    //6插入现金流水表
    //7更新用户现金表
    public function handleRequest()
    {
	    $result = ['error' => '出错啦', 'code' => 10001];

	    DB::beginTransaction();
	    try
	    {
		    $this->setSuccessor(new CheckIdentityVerifyAction($this->params));
		    $result = $this->getSuccessor()->handleRequest();
		    if (isset($result['error'])) {
			    DB::rollback();
			    SLogger::getStream()->error('资料完成添加积分失败-try');
			    SLogger::getStream()->error($result['error']);
		    }
		    else
		    {
			    DB::commit();
		    }
	    }
	    catch (\Exception $e)
	    {
		    DB::rollBack();

		    SLogger::getStream()->error('资料完成添加积分失败-catch');
		    SLogger::getStream()->error($e);
	    }
	    return $result;
    }

}
